package cn.lang.producer.controller;

import cn.lang.global.ret.Ret;
import cn.lang.global.validator.Add;
import cn.lang.global.validator.ValidatorUtil;
import cn.lang.oss.handler.OssHelloHandler;
import cn.lang.producer.dto.Menu;
import cn.lang.producer.dto.UserDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

@RestController
public class TestController {

    Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private OssHelloHandler ossHelloHandler;

    @RequestMapping("/tes")
    public void tes(){
        File file = new File("D:\\JavaGuide-main\\docs\\database\\mysql\\images\\mvvc\\c52ff79f-10e6-46cb-b5d4-3c9cbcc1934a.png");
        String upload = ossHelloHandler.upload(file);
    }

    @GetMapping("/test")
    public String test(@Validated UserDto userDto) {
        logger.info("provide test");
        return "test";
    }

    @GetMapping("/test2")
    public String test2(@Validated UserDto userDto) {
        ValidatorUtil.validate(userDto, Add.class);
        logger.info("provide test");
        return "test";
    }
    @RequestMapping("/test3")
    public UserDto test3(){
        UserDto<Menu> userDto = new UserDto();
        userDto.setAge(1);
        Menu menu = new Menu();
        menu.setM("sad");
        userDto.setData(menu);
        return userDto;
    }
}
